package com.yao.controller;

import com.yao.req.EbookQueryReq;
import com.yao.req.EbookReq;
import com.yao.req.EbookSaveReq;
import com.yao.resp.CommonResp;
import com.yao.resp.EbookQueryResp;
import com.yao.resp.EbookResp;
import com.yao.resp.PageResp;
import com.yao.service.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author : hzyao
 * @date : 17:41 2021/7/27
 */
@RestController
@RequestMapping("/ebook")
public class EbookController {
    @Resource
    private EbookService ebookService;

    @GetMapping("/hello")
    public String hello() {
        return "Hello World!" ;
    }


    @GetMapping("/list")
    public CommonResp list( EbookQueryReq req) {
        CommonResp<PageResp<EbookQueryResp>> resp = new CommonResp();
        PageResp<EbookQueryResp> list = ebookService.list(req);
        resp.setContent(list);
        return resp;

    }
    @PostMapping("/save")
    public CommonResp save( @RequestBody EbookSaveReq req) {
        CommonResp resp = new CommonResp<>();
        ebookService.save(req);
        return resp;
    }
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);
        return resp;
    }



}
